[HVM] Save/restore cleanups 05: save-format headers
authorTim Deegan <Tim.Deegan@xensource.com>
Sat, 20 Jan 2007 11:17:42 +0000 (11:17 +0000)
committerTim Deegan <Tim.Deegan@xensource.com>
Sat, 20 Jan 2007 11:17:42 +0000 (11:17 +0000)
Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
xen/arch/x86/hvm/intercept.c
xen/include/public/hvm/save.h

index 086a4d68e0e25671e56f5edfc2a6afd91cc0d71c..9a454c6290a91742bc0779cd0d4fbf33d2a7b743 100644 (file)
@@ -157,9 +157,6 @@ static inline void hvm_mmio_access(struct vcpu *v,
     }
 }
 
-/* save/restore support */
-#define HVM_FILE_MAGIC   0x54381286
-#define HVM_FILE_VERSION 0x00000001
 
 int hvm_register_savevm(struct domain *d,
                     const char *idstr,
@@ -199,6 +196,7 @@ int hvm_save(struct vcpu *v, hvm_domain_context_t *h)
     uint32_t eax, ebx, ecx, edx;
     HVMStateEntry *se;
     char *chgset;
+    struct hvm_save_header hdr;
 
     if (!is_hvm_vcpu(v)) {
         printk("hvm_save only for hvm guest!\n");
@@ -206,8 +204,12 @@ int hvm_save(struct vcpu *v, hvm_domain_context_t *h)
     }
 
     memset(h, 0, sizeof(hvm_domain_context_t));
-    hvm_put_32u(h, HVM_FILE_MAGIC);
-    hvm_put_32u(h, HVM_FILE_VERSION);
+
+    hdr.magic = HVM_FILE_MAGIC;
+    hdr.version = HVM_FILE_VERSION;
+    cpuid(1, &eax, &ebx, &ecx, &edx);
+    hdr.cpuid = eax;
+    hvm_put_struct(h, &hdr);
 
     /* save xen changeset */
     chgset = strrchr(XEN_CHANGESET, ' ');
@@ -220,10 +222,6 @@ int hvm_save(struct vcpu *v, hvm_domain_context_t *h)
     hvm_put_8u(h, len);
     hvm_put_buffer(h, chgset, len);
 
-    /* save cpuid */
-    cpuid(1, &eax, &ebx, &ecx, &edx);
-    hvm_put_32u(h, eax);
-
     for(se = v->domain->arch.hvm_domain.first_se; se != NULL; se = se->next) {
         /* ID string */
         len = strnlen(se->idstr, HVM_SE_IDSTR_LEN);
@@ -274,13 +272,14 @@ static HVMStateEntry *find_se(struct domain *d, const char *idstr, int instance_
 
 int hvm_load(struct vcpu *v, hvm_domain_context_t *h)
 {
-    uint32_t len, rec_len, rec_pos, magic, instance_id, version_id;
+    uint32_t len, rec_len, rec_pos, instance_id, version_id;
     uint32_t eax, ebx, ecx, edx;
     HVMStateEntry *se;
     char idstr[HVM_SE_IDSTR_LEN];
     xen_changeset_info_t chgset;
     char *cur_chgset;
     int ret;
+    struct hvm_save_header hdr;
 
     if (!is_hvm_vcpu(v)) {
         printk("hvm_load only for hvm guest!\n");
@@ -294,18 +293,28 @@ int hvm_load(struct vcpu *v, hvm_domain_context_t *h)
 
     hvm_ctxt_seek(h, 0);
 
-    magic = hvm_get_32u(h);
-    if (magic != HVM_FILE_MAGIC) {
+    hvm_get_struct(h, &hdr);
+
+    if (hdr.magic != HVM_FILE_MAGIC) {
         printk("HVM restore magic dismatch!\n");
         return -1;
     }
 
-    magic = hvm_get_32u(h);
-    if (magic != HVM_FILE_VERSION) {
+    if (hdr.version != HVM_FILE_VERSION) {
         printk("HVM restore version dismatch!\n");
         return -1;
     }
 
+    /* check cpuid */
+    cpuid(1, &eax, &ebx, &ecx, &edx);
+    /*TODO: need difine how big difference is acceptable */
+    if (hdr.cpuid != eax)
+        printk("warnings: try to restore hvm guest(0x%"PRIx32") "
+               "on a different type processor(0x%"PRIx32").\n",
+                hdr.cpuid,
+                eax);
+
+
     /* check xen change set */
     cur_chgset = strrchr(XEN_CHANGESET, ' ');
     if ( cur_chgset )
@@ -330,16 +339,6 @@ int hvm_load(struct vcpu *v, hvm_domain_context_t *h)
         printk("warnings: try to restore hvm guest when changeset is unavailable.\n");
 
 
-    /* check cpuid */
-    cpuid(1, &eax, &ebx, &ecx, &edx);
-    ebx = hvm_get_32u(h);
-    /*TODO: need difine how big difference is acceptable */
-    if (ebx != eax)
-        printk("warnings: try to restore hvm guest(0x%"PRIx32") "
-               "on a different type processor(0x%"PRIx32").\n",
-                ebx,
-                eax);
-
     while(1) {
         if (hvm_ctxt_end(h)) {
             break;
index 367b3ec0a77ce1178b85870ed9f6e1cbec752829..9bd3e05667ed0a2828f090a97aeceee6f04991b2 100644 (file)
  * Internal mechanisms should be kept in Xen-private headers.
  */
 
+/* 
+ * Save/restore header
+ */
+
+#define HVM_SAVE_TYPE_HEADER 0
 
+#define HVM_FILE_MAGIC   0x54381286
+#define HVM_FILE_VERSION 0x00000001
+
+struct hvm_save_header {
+    uint32_t magic;
+    uint32_t version;
+    uint32_t cpuid;
+};
 
 /*
  * Processor